﻿// Copyright © Microsoft Corporation.  All Rights Reserved.
// This code released under the terms of the 
// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Administration;

namespace Microsoft.MCSUK.SPSiteDirectory2010
{
    public class ScanJobSettings : SPPersistedObject
    {
        [Persisted]
        public Boolean UseSiteOwnersGroup;
        [Persisted]
        public Boolean UseManageWebPermission;
        [Persisted]
        public Boolean UserSiteCollectionAdministrators;
        [Persisted]
        public Boolean IsScanJobConfigured;
        [Persisted]
        public Guid JobDefinitionGUID;
        [Persisted]
        public String ExclusionURLs;
        [Persisted]
        public Boolean UseSiteLogo;
        [Persisted]
        public Boolean IncludeSubSites;
        [Persisted]
        public Boolean EnsureSiteLogo;
        [Persisted]
        public string DefaultLogoURL;
        public ScanJobSettings() { }
        public ScanJobSettings(string name, SPPersistedObject parent, Guid id) : base(name, parent, id) { }

        protected override bool HasAdditionalUpdateAccess()
        {
            return true;
        }

        public ScanJobSettings GetOrCreateScanJobSettings(SPWebApplication webApplication)
        {
            ScanJobSettings scanJobSettings = webApplication.GetChild<ScanJobSettings>(webApplication.Id.ToString());
            try
            {
                if (scanJobSettings == null)
                {
                    SPPersistedObject parent = webApplication;
                    scanJobSettings = new ScanJobSettings(webApplication.Id.ToString(), parent, Guid.NewGuid());
                    scanJobSettings.Update();
                }
            }
            catch (Exception ex)
            {
                GlobalMethods globalMethods = new GlobalMethods();
                globalMethods.WriteULSEntry(ex, TraceSeverity.Unexpected, null);
            }
            return scanJobSettings;
        }
    }
}
